package util

import "math/rand"

// 生成随机数
func Random(m int , n int) int {
	randomInt := rand.Intn(m)+n
	return randomInt
}

// 碰撞检测
func IsColliding(birdX, birdY float64, birdWidth, birdHeight float64, barrierX, barrierTopY, barrierBottomY float64, barrierWidth int,HoverUp float64,HoverBottom float64) bool {
	birdLeft := birdX
	birdTop := birdY
	birdRight := birdLeft + birdWidth
	birdBottom := birdTop + birdHeight

	barrierLeft := barrierX
	barrierTop := barrierTopY
	barrierRight := barrierLeft + float64(barrierWidth)
	barrierBottom := barrierBottomY

	if birdRight < barrierLeft || birdLeft > barrierRight || ((birdBottom < barrierBottom) && (birdTop > barrierTop)) || ((birdBottom < HoverUp) || (birdTop > HoverBottom+20)) {
		// 没有碰撞
		return false
	}

	// 有碰撞
	return true
}


